package com.auto.survey.activity.test

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.auto.survey.R

/**
 * 抽屉adapter，
 * 功能：显示蓝牙通信日志
 */
class DrawerAdapter: Adapter<DrawerAdapter.DrawerViewHoder>() {

    private var mData:MutableList<String>?=null

    fun setDrawerItems(items: MutableList<String>) {
        mData = items
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DrawerViewHoder {
        val itemview = LayoutInflater.from(parent.context).inflate(R.layout.item_test_drawer, parent, false)
        return  DrawerViewHoder(itemview)
    }

    override fun getItemCount(): Int {
        if (mData != null && mData!!.size> 0) {
            return mData!!.size
        }
        return 0
    }

    override fun onBindViewHolder(holder: DrawerViewHoder, position: Int) {
        holder.tv_item_test_drawer.text = mData?.get(position) ?: ""
    }

    class DrawerViewHoder(item:View):ViewHolder(item){
        val tv_item_test_drawer = item.findViewById<TextView>(R.id.tv_item_test_drawer)
    }

}